{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "517d977e",
   "metadata": {},
   "source": [
    "# 幅值估计和填零\n",
    "此示例说明如何使用填零来获得正弦信号幅值的精确估计。离散傅里叶变换 (DFT) 中频率的间隔为 Fs/N，其中 Fs是采样率，N 是输入时间序列的长度。在尝试估计正弦波幅值时，如果频率无法对应到 DFT bin，则可能导致估计不准确。\n",
    "在计算 DFT 之前对数据填零通常有助于提高幅值估计的准确度。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d3561e15",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy.fft import fft\n",
    "import numpy as np\n",
    "from numpy import ndarray, cos, sin, abs\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8d75943e",
   "metadata": {},
   "source": [
    "创建由两个正弦波组成的信号。这两个正弦波的频率分别为 100 和 202.5 Hz。采样率为 1000 Hz，信号长度为 1000 个采样点。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ca3323a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_data():\n",
    "    # 生成时间序列(0到1之间生成1000个数据点)\n",
    "    t = np.arange(0, 1, 0.001)\n",
    "    # 生成信号(broadcast机制)\n",
    "    data = cos(2 * np.pi * 100 * t) + sin(2 * np.pi * 202.5 * t)\n",
    "    return data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c79ae90",
   "metadata": {},
   "source": [
    "获取信号的 DFT。DFT bin 的间距为 1 Hz。相应地，100 Hz 正弦波对应到一个 DFT bin，但 202.5 Hz 正弦波无法对应。\n",
    "\n",
    "由于信号是实数值信号，此处只使用 DFT 的正频率来估计幅值。按输入信号的长度缩放 DFT，并将 0 和奈奎斯特之外的所有频率乘以 2。\n",
    "\n",
    "绘制结果并与已知幅值进行比较。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9afce853",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_freq_amplitude(input_data: ndarray, N, fs):\n",
    "    # 对输入信号进行fft变换得到双边频谱\n",
    "    data_dft = fft(input_data, N)\n",
    "    # 数据点数\n",
    "    data_num = len(input_data)\n",
    "    # 截取一半(此处根据python和matlab检索不同来做一些调整)\n",
    "    data_dft = data_dft[0:int(N / 2) + 1]\n",
    "    # 修改一下幅度\n",
    "    data_dft = data_dft / data_num\n",
    "    data_dft[1:] = 2 * data_dft[1:]\n",
    "    # 配置频率横轴(python生成等比序列是不包含结束点的,因此加一个特别小的数)\n",
    "    freq = np.arange(0.0, fs / 2 + 0.0001, fs / N)\n",
    "    data_dft = abs(data_dft)\n",
    "    return data_dft, freq\n",
    "\n",
    "\n",
    "def plot_signal_freq_amplitude(data_dft, freq):\n",
    "    fig = plt.figure()\n",
    "    plt.plot(freq, data_dft)\n",
    "    plt.xlabel(\"Hz\")\n",
    "    plt.ylabel(\"Amplitude\")\n",
    "    plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "41aa66b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcU0lEQVR4nO3de5QcZ33m8e+ve2662bKkkcG6eCRFliOI7ZixbBayCCdxZMdYyWYTbC8BOySKCWZJ9gLOyW44OeGckBCywOKg1Rrb5MCizSYmlkHg+JiLOYBBsvFFQrYZXbDHEtZohHUZpLn1b/+o6lFNq6emezQ1PVPv8zmnT3dduud9pZn3qfeteqvN3RERkXAVGl0AERFpLAWBiEjgFAQiIoFTEIiIBE5BICISuKZGF6BeixYt8o6OjkYXQ0RkRnniiSeOuHt7tW0zLgg6OjrYuXNno4shIjKjmNmPx9qmoSERkcApCEREAqcgEBEJnIJARCRwCgIRkcApC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wszW1/KWKutmVJ1jb3L3g2a2GHjEzJ5L2XfS6hxKj6AbWJZYXgocbFBZpsIrZvZagPj5cLw+F/8OZtZMFAKfd/cH4tW5rnOZu78KfAPYQL7r/CbgJjM7QDSUe62ZfY581xl3Pxg/Hwa+SDTUk3mdQwmCHcBqM1thZi3AzcC2BpcpS9uAd8Wv3wU8mFh/s5m1mtkKYDXw/QaUb8IsOvT/DLDH3f8usSnPdW6PewKY2SzgV4DnyHGd3f1P3X2pu3cQ/b1+zd3fQY7rbGZzzGxe+TVwHbCLqahzo8+ST+HZ+BuIrjDZC/xZo8szifX6AnAIGCQ6Qng3sBB4FPhR/Lwgsf+fxf8GzwPXN7r8E6jvm4m6v88AT8WPG3Je58uAH8R13gX8ebw+t3WuqP96zlw1lNs6E13V+HT82F1up6aizrrFhIhI4EIZGhIRkTEoCEREAqcgEBEJnIJARCRwCgIRkcApCEQmwMxOVizfZmafalR5RM6FgkBEJHCh3GtIZMrEN4crWwNscPdvNqg4IuNSEIhMzKyKBn8B8W1L3P0KADN7G9HdM78z1YUTqYeCQGRiTpUbfIjOEQCdieXVwEeBa919cMpLJ1IHnSMQmWTxDcP+EfgDj+8mKTKdKQhEJt99wH3u/q1GF0SkFgoCkUlkZhcD/x74vfgLyJ8ys87x3ifSSLr7qIhI4NQjEBEJnIJARCRwCgIRkcApCEREAqcgEBEJnIJARCRwCgIRkcD9f09wiXrS6WugAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAcE0lEQVR4nO3dfbRcdX3v8fd3Zs7JCYQ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SWvr4iHZ+rn4OZLQJ+jmQNOdc1p7tI1gE7gTvdPfc1A58H/ggoV43Le80O3GFmD5jZsnRc5jVn+mCa44jVGRfxvNnc/BzMbBbwDeAP3P1Fs3qlJbPWGTftanb3ceAcM5sDfNPM3tBg9mlfs5m9G9jp7g+Y2QXNfKTOuGlVc+o8d99uZq8A7jSzxxvM27Gao2wRDAELqobnA9t71JZueNbMTgdIX3em43PxczCzPpIQuNndb0lH57rmCnffDXwXWEq+az4PeK+ZPUWyK/dCM/sa+a4Zd9+evu4EvkmyqyfzmqMEwRpgiZktNrN+4DJgVY/blKVVwG+l738LuLVq/GVmNsPMFgNLgB/1oH1TZsmq/1eAje7+11WT8lzz3HRLADObCfwS8Dg5rtnd/9jd57v7IpL/17vc/TfJcc1mdqKZnVR5D1wEPEo3au71UfIuHo2/hOQMkx8Df9Lr9nSwrn8EdgCjJGsIHwFeDnwH2Jy+nlI1/5+kP4NNwMW9bv8U6j2fZPP3YWBd+nVJzmt+I/BQWvOjwJ+l43Nbc039F3D4rKHc1kxyVuP69GtDpZ/qRs26xYSISHBRdg2JiMgkFAQiIsEpCEREglMQiIgEpyAQEQlOQSAyBWb2Us3wh83si71qj0g7FAQiIsFFudeQSNekN4ereB2w1N3v6VFzRI5JQSAyNTNrOvxTSG9b4u7nAJjZe0junvn9bjdOpBUKApGpOVDp8CE5RgAMVg0vAT4DXOjuo11vnUgLdIxApMPSG4b9E/C7nt5NUuR4piAQ6bwbgRvd/b5eN0SkGQoCkQ4yszOA9wG/nT6AfJ2ZDR7rcyK9pLuPiogEpy0CEZHgFAQiIsEpCEREglMQiIgEpyAQEQlOQSAiEpyCQEQkuP8PHSj0plft7jMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    # 设置采样率\n",
    "    fs = 1000\n",
    "    # 构造数据\n",
    "    data = generate_data()\n",
    "    # 数据点数\n",
    "    N = len(data)\n",
    "    # 获取补零前的幅频以及对应的频率轴\n",
    "    data_dft, freq = get_freq_amplitude(data, N, fs)\n",
    "    # 绘制波形\n",
    "    plot_signal_freq_amplitude(data_dft, freq)\n",
    "    # 获取补零后的序列的幅频以及对应的频率轴\n",
    "    data_padding_dft, freq_padding = get_freq_amplitude(data, 2 * N, fs)\n",
    "    # 绘制波形\n",
    "    plot_signal_freq_amplitude(data_padding_dft, freq_padding)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9fd27f18",
   "metadata": {},
   "source": [
    "100 Hz 的幅值估计是准确的，因为该频率对应到一个 DFT bin。然而，202.5 Hz 的幅值估计并不准确，因为该频率无法对应到一个 DFT bin。\n",
    "\n",
    "您可以通过填零对 DFT 插值。填零使您能够获得可分辨信号分量的更精确幅值估计。另一方面，填零并不能提高 DFT 的频谱（频率）分辨率。分辨率由采样点数量和采样率决定。\n",
    "\n",
    "将 DFT 的长度填充到 2000，即 x 原始长度的两倍。使用此长度时，DFT bin 的间距是 Fs/2000=0.5Hz。此时，202.5 Hz 正弦波的能量正好落入一个 DFT bin。获得 DFT 并绘制幅值估计。填零以使采样点数量达到 2000。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "712329d3",
   "metadata": {},
   "source": [
    "通过填零，可以对这两个频率的幅值都做出正确估计。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
